package ca.jerg.wizard;

import ca.jerg.config.*;

public class ErgWizardSetData
{
	private String type;	
	private double thresholdWatts;
	private int repeats;
	private double workTime;
	private double restTime;
	private double workLoad;
	private double restLoad;
	private double rampTime;
	
	public ErgWizardSetData( String type, int repeats )
	{
		this.type = type;
		this.repeats = repeats;
	}
	
	public void calculateSet()
	{
		// work time & rest time multipliers
		ErgConfigWorkTime timeWork = new ErgConfigWorkTime();
		ErgConfigRest timeRest = new ErgConfigRest();
		
		// work & rest loads
		ErgConfigWork loadWork = new ErgConfigWork();
		
		workTime = timeWork.getDouble(type,getDefaultWorkTime());
		restTime = workTime * timeRest.getDouble(type,getDefaultRestTime());
		
		workLoad = thresholdWatts * loadWork.getDouble(type,getDefaultLoad());
		restLoad = thresholdWatts * loadWork.getDouble(IErgConfig.KEY_REST,getDefaultLoad());
		
		// ramp up to work load time
		rampTime = timeWork.getDouble(IErgConfig.KEY_RAMP,ErgConfigWorkTime.DEF_RAMP_TIME);
	}
	
	public void setThresholdWatts( double watts )
	{
		thresholdWatts = watts;
	}
	
	private double getDefaultLoad()
	{
		if ( type.equals(IErgConfig.KEY_ANAEROBIC) )
			return ErgConfigWork.DEF_ANAEROBIC_LOAD;
		
		if ( type.equals(IErgConfig.KEY_VO2) )
			return ErgConfigWork.DEF_VO2_LOAD;
		
		if ( type.equals(IErgConfig.KEY_FT) )
			return ErgConfigWork.DEF_FT_LOAD;
		
		if ( type.equals(IErgConfig.KEY_TEMPO) )
			return ErgConfigWork.DEF_TEMPO_LOAD;
		
		if ( type.equals(IErgConfig.KEY_DISTANCE) )
			return ErgConfigWork.DEF_DISTANCE_LOAD;
		
		if ( type.equals(IErgConfig.KEY_REST) )
			return ErgConfigWork.DEF_REST_LOAD;		
		
		return 0.0;
	}

	private double getDefaultWorkTime()
	{
		if ( type.equals(IErgConfig.KEY_ANAEROBIC) )
			return ErgConfigWorkTime.DEF_ANAEROBIC_TIME;
		
		if ( type.equals(IErgConfig.KEY_VO2) )
			return ErgConfigWorkTime.DEF_VO2_TIME;
		
		if ( type.equals(IErgConfig.KEY_FT) )
			return ErgConfigWorkTime.DEF_FT_TIME;
		
		if ( type.equals(IErgConfig.KEY_TEMPO) )
			return ErgConfigWorkTime.DEF_TEMPO_TIME;
		
		if ( type.equals(IErgConfig.KEY_DISTANCE) )
			return ErgConfigWorkTime.DEF_DISTANCE_TIME;
		
		return 0.0;
	}	
	
	private double getDefaultRestTime()
	{
		if ( type.equals(IErgConfig.KEY_ANAEROBIC) )
			return ErgConfigRest.DEF_ANAEROBIC_REST;
		
		if ( type.equals(IErgConfig.KEY_VO2) )
			return ErgConfigRest.DEF_VO2_REST;
		
		if ( type.equals(IErgConfig.KEY_FT) )
			return ErgConfigRest.DEF_FT_REST;
		
		if ( type.equals(IErgConfig.KEY_TEMPO) )
			return ErgConfigRest.DEF_TEMPO_REST;
		
		if ( type.equals(IErgConfig.KEY_DISTANCE) )
			return ErgConfigRest.DEF_DISTANCE_REST;
		
		return 0.0;
	}	

	/**
	 * @return the type
	 */
	public String getType()
	{
		return type;
	}
	/**
	 * @param type the type to set
	 */
	public void setType( String type )
	{
		this.type = type;
	}
	/**
	 * @return the repeats
	 */
	public int getRepeats()
	{
		return repeats;
	}
	/**
	 * @param repeats the repeats to set
	 */
	public void setRepeats( int repeats )
	{
		this.repeats = repeats;
	}

	/**
	 * @return the workTime
	 */
	public double getWorkTime()
	{
		return workTime;
	}

	/**
	 * @return the restTime
	 */
	public double getRestTime()
	{
		return restTime;
	}

	/**
	 * @return the workLoad
	 */
	public double getWorkLoad()
	{
		return workLoad;
	}

	/**
	 * @return the restLoad
	 */
	public double getRestLoad()
	{
		return restLoad;
	}

	/**
	 * @return the rampTime
	 */
	public double getRampTime()
	{
		return rampTime;
	}
}
